using System;

namespace NumSkull
{
    public class HistogramBinValue : IEquatable<HistogramBinValue>
    {
        public HistogramBinValue(double value)
            : this(value, 1)
        { }

        public HistogramBinValue(double value, int count)
        {
            Value = value;
            Count = count;
        }

        public double Value { get; set; }
        public int Count { get; set; }

        public bool Equals(HistogramBinValue other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;

            var isEqual = Equals(other.Value, Value) && Equals(other.Count, Count);
            return isEqual;
        }

        public override bool Equals(object obj)
        {
            var binValue = obj as HistogramBinValue;
            return Equals(binValue);
        }

        public override int GetHashCode()
        {
            unchecked
            {
                var hashCode =  (Value.GetHashCode() * 397) ^ Count;
                return hashCode;
            }
        }
    }
}